package com.ruoyi.app.controller;

import com.ruoyi.app.domain.RestockInfo;
import com.ruoyi.app.domain.vo.OrderInfoVo;
import com.ruoyi.app.domain.vo.RestockInfoVo;
import com.ruoyi.app.service.IRestockInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 进货单Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/restock/restockInfo")
public class RestockInfoController extends BaseController
{
    @Autowired
    private IRestockInfoService restockInfoService;

    /**
     * 查询进货单列表
     */
//    @PreAuthorize("@ss.hasPermi('restock:restockInfo:list')")
    @GetMapping("/list")
    public AjaxResult list(RestockInfoVo restockInfoVO)
    {
//        startPage();
//        List<RestockInfo> list = restockInfoService.selectRestockInfoList(restockInfo);
//        return getDataTable(list);
        startPage();
        restockInfoVO.setShopId(getShopId());
        List<RestockInfoVo> list = restockInfoService.selectRestockInfoList(restockInfoVO);
        return success(getDataTable(list));
    }

    /**
     * 导出进货单列表
     */
    @PreAuthorize("@ss.hasPermi('restock:restockInfo:export')")
    @Log(title = "进货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RestockInfoVo restockInfo)
    {
        List<RestockInfoVo> list = restockInfoService.selectRestockInfoList(restockInfo);
        ExcelUtil<RestockInfoVo> util = new ExcelUtil<RestockInfoVo>(RestockInfoVo.class);
        util.exportExcel(response, list, "进货单数据");
    }

    /**
     * 获取进货单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('restock:restockInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(restockInfoService.selectRestockInfoById(id));
    }

    /**
     * 新增进货单
     */
//    @PreAuthorize("@ss.hasPermi('restock:restockInfo:add')")
//    @Log(title = "进货单", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    public AjaxResult add(@RequestBody RestockInfo restockInfo)
//    {
//        return toAjax(restockInfoService.save(restockInfo));
//    }

    /**
     * 修改进货单
     */
    @PreAuthorize("@ss.hasPermi('restock:restockInfo:edit')")
    @Log(title = "进货单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody RestockInfo restockInfo)
    {
        return toAjax(restockInfoService.updateById(restockInfo));
    }

    /**
     * 删除进货单
     */
//    @PreAuthorize("@ss.hasPermi('restock:restockInfo:remove')")
    @Log(title = "进货单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(restockInfoService.removeByIds(objects));
    }

    /**
     * 新增订单详情
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody RestockInfoVo restockInfoVo)
    {
        restockInfoVo.setPeopleId(getUserId());
        restockInfoVo.setPeopleName(getUsername());
        restockInfoVo.setShopId(getShopId());
        return success().setData(restockInfoService.add(restockInfoVo));
    }


    /**
     * 统计分析
     */
    @GetMapping("/statistics")
    public AjaxResult statistics(RestockInfoVo restockInfoVo)
    {
        restockInfoVo.setShopId(getShopId());
        List<RestockInfoVo> list = restockInfoService.statistics(restockInfoVo);
        return success(getDataTable(list));
    }

    /**
     * 统计分析 采购订单详情
     */
    @GetMapping("/statisticsInfo")
    public AjaxResult statisticsInfo(RestockInfoVo restockInfoVo)
    {
        restockInfoVo.setShopId(getShopId());
        RestockInfoVo infoVo = restockInfoService.statisticsInfo(restockInfoVo);
        return success(infoVo);
    }

}
